package kaizone.haining.chaobohui.json;

import org.json.JSONObject;

public class Pagination {
    
    public static final String MAXPAGES = "maxPages";
    public static final String PAGE = "page";
    public static final String SIZE = "size";
    public static final String START = "start";
    public static final String TOTALPAGES = "totalPages";
    
    public int maxPages;
    public int page;
    public int size;
    public int start;
    public int totalPages;
    
    public static Pagination parse(JSONObject jsonObject){
        Pagination pagination = new Pagination();
        pagination.maxPages = jsonObject.optInt(Pagination.MAXPAGES);
        pagination.page = jsonObject.optInt(Pagination.PAGE);
        pagination.size = jsonObject.optInt(Pagination.SIZE);
        pagination.start = jsonObject.optInt(Pagination.START);
        pagination.totalPages = jsonObject.optInt(Pagination.TOTALPAGES);
        return pagination;
    }
    
    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("maxPages").append(":").append(maxPages).append("\n");
        sb.append("page").append(":").append(page).append("\n");
        sb.append("size").append(":").append(size).append("\n");
        sb.append("start").append(":").append(start).append("\n");
        sb.append("totalPages").append(":").append(totalPages).append("\n");
        return sb.toString();
    }
}
